package palms.client.android.overlay;

import palms.client.domain.User;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.location.Location;
import android.location.LocationManager;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.Projection;

public class UserLocation extends MyLocationOverlay {
	
	private User myuser;

	
	public UserLocation(Context context, MapView mapView, User user) {   
		super(context, mapView);
		this.myuser = user;		
	}  
		
	@Override
	public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when){
		
		GeoPoint gp = new GeoPoint((int)(this.myuser.getLatitude()*1E6), (int)(this.myuser.getLongitude()*1E6));
		Location l = new Location(LocationManager.GPS_PROVIDER);
		l.setLatitude(gp.getLatitudeE6()/1E6);
		l.setLongitude(gp.getLongitudeE6()/1E6);
		
		Projection p = mapView.getProjection();
		Paint paint = new Paint();
		Point point = new Point();
		p.toPixels(gp, point);
		paint.setColor(Color.BLUE);
		paint.setColor(Color.BLUE);
		paint.setStrokeWidth(5); 
		paint.setAlpha(15);
		canvas.drawCircle(point.x, point.y, p.metersToEquatorPixels(600), paint);
		
	
		super.drawMyLocation(canvas, mapView, l, gp, when);

		
		return true;
		
	}
	
}
